<?php
namespace app\center\controller;
use app\center\logic\UserLogic;

/**
 * 用户api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/09
 * Time: 15:02
 */
class User extends Base {

    public function __construct(){
        parent::__construct();
        $this->u_logic = new UserLogic();
    }

    /**
     * 获取用户
     * @return \think\response\Json
     */
    public function ajax_get_user(){
        $params = input();
        $r = $this->check_user_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        //检查用户规则
        $r = $this->u_logic->check_user_rule();
        if($r['code'] != 1){
            return json($r);
        }
        $u_detail = $r['data']['detail'];

        $maps = $this->u_logic->get_search_user_maps($u_detail['openid']);

        $list = model('user')->get_list($maps,'id,openid,username','id desc');
        foreach($list as $k => $v){
            $v_maps = [];
            $v_maps[] = ['openid','=',$v['openid']];
            $v_detail = model('visitor')->get_detail($v_maps,'id,headimgurl');
            $list[$k]['headimgurl'] = $v_detail['headimgurl'];
        }

        $data['list'] = $list;
        return json($this->u_logic->get_response(1,'OK',$data));
    }
}
